#pragma once

#include <stdint.h>

/**
 * @brief 舵机角度
 *
 */
typedef enum sg90_angel
{
    SG90_ANGEL_0 = 0, /* 0 度 */
    SG90_ANGEL_45,    /* 45 度 */
    SG90_ANGEL_90,    /* 90 度 */
    SG90_ANGEL_135,   /* 135 度 */
    SG90_ANGEL_180,   /* 180 度 */
} sg90_angel_e;

/**
 * @brief Initialize the PWM pin used for SG90 servo motor.
 *
 * This function initializes the specified PWM pin for controlling an SG90 servo motor.
 *
 * @param[in] pwm_pin The PWM pin number to initialize.
 * @return int Returns 0 on success, or a negative error code on failure.
 */
int sg90_init(int pwm_pin);

/**
 * @brief Deinitialize the PWM pin used for SG90 servo motor.
 *
 * This function stops and releases the resources of the specified PWM pin, typically called when the servo is no longer needed.
 *
 * @param[in] pwm_pin The PWM pin number to deinitialize.
 * @return int Returns 0 on success, or a negative error code on failure.
 */
int sg90_deinit(int pwm_pin);

/**
 * @brief Set the angle of the SG90 servo motor.
 *
 * This function sets the SG90 servo motor connected to the specified PWM pin to rotate to the target angle.
 *
 * @param[in] pwm_pin The PWM pin number where the servo is connected.
 * @param[in] angel   The target angle to set, refer to [sg90_angel_e]
 * @return int Returns 0 on success, or a negative error code on failure.
 */
int sg90_set_angel(int pwm_pin, sg90_angel_e angel);

